use student::*;
use teacher::*;
use hello_macro_derive::HelloMacro;
use attr_macro::route;
use func_macro::array;

pub trait Hello{
    fn hello_macro();
    fn showme(&self)->String;
    fn get_name(&self)->String;
}

#[derive(Debug, HelloMacro)]
struct Home{
    name: String,
    age: u32,
}

fn main() {
    //1.测试其它单元包的使用情况
    test_other_crate();
    //2.测试盒子指针
    let _me = Box::new(String::from("中国"));

    let lu = Teacherinfo {
        name: String::from("lu"),
        age: 46,
        gender: String::from("男"),
        position: String::from("教研组长"),
    };
    let my_lu = MyTeacherinfo(lu);
    my_lu.print();

    //3.测试用户自定义的各种宏    
    println!("\n\n测试用户自定义的derive宏-----------------------");
    // 宏helloMacro具有3个方法，分别是showme, get_name和hello_macro
    test_udf_derive_macro();
    println!("\n测试用户自定义的类属性宏-----------------------");
    test_attr_macro();
    println!("\n测试用户自定义的类函数宏-----------------------");
    test_func_macro();
}

struct MyTeacherinfo(Teacherinfo);
impl Print for MyTeacherinfo {
    fn print(&self) {
        println!(
            "教师基本信息-姓名:{},年龄:{},性别:{},职位:{}",
            self.0.name, self.0.age, self.0.gender, self.0.position
        );
    }
}

/**
 * 测试用户自定义的derive宏
 */
fn test_udf_derive_macro(){
    let home = Home{name: String::from("home"), age: 18};
    let me=home.showme();
    println!("{}", me);
    println!("{}", home.get_name());
    Home::hello_macro();
}
#[route(GET,"/")]
fn test_attr_macro() {
}

fn test_func_macro() {
    let arr = array!("1,2,3,4,5",",");
    println!("{:?}",arr);
}   


/**
 * 测试对其它单元包的使用
 */
fn test_other_crate(){
    let lml = Studentinfo {
        name: String::from("lml"),
        age: 18,
        gender: String::from("女"),
        no: String::from("12101"),
    };
    print_student(&lml);
    lml.learn();
    lml.sleep();

    let lu = Teacherinfo {
        name: String::from("lu"),
        age: 46,
        gender: String::from("男"),
        position: String::from("教研组长"),
    };
    lu.teach_student(&lml);
    print_teacher(&lu);
}

// 以下代码违反了孤儿原则，因为Teacherinfo和Print不是当前单元包的，也不是位于std中例外存在
// impl Print for Teacherinfo{
//     fn print(&self){
//         println!("{}",self.name);
//     }
// }
